import React from 'react'
import Child from './Child'
import {Button} from 'antd'
export default class Life extends React.Component{

    constructor(props) {
        super(props);
        this.state = {
            date: new Date(),
            count:0,
            comment:'fdf'
        };
    }

    handAddClick = () =>{
        // 这样使用不行
        // this.setState({
        //     count: this.state.cout + 1   //https://reactjs.org/docs/state-and-lifecycle.html 官网
        // })
        this.setState({
            comment: 'Hello',
        });
        this.setState((prevState, props) => ({
            count: prevState.count + 1
        }));
        console.log('handAddClick')
    }
    handAdd(){
        // this.setState({
        //     count:this.state.cout+1
        // })
        this.setState((prevState, props) => ({
            count: prevState.count + 1
        }));
        console.log('handAdd')
    }
    render(){
        return <div style={{padding:50}}>
            <div>神不在的星期天</div>
            <button onClick={this.handAddClick}>点击一下</button>
            <button onClick={this.handAdd.bind(this)}>(第二个)点击一下</button>
            <Button onClick={this.handAdd.bind(this)}> antd</Button>
            <p >{this.state.date.toLocaleDateString()}</p>
            <p>{this.state.count}</p>
            <p>{this.state.comment}</p>
        <Child name={this.state.count}/>
        </div>
    }
}